//
//  MYHomeReweetView.swift
//  NewMicroblog
//
//  Created by apple on 2016/10/26.
//  Copyright © 2016年 apple. All rights reserved.
//

import UIKit

class MYHomeReweetView: UIView {
    
     var retweetViewCons: Constraint?
   
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    var statusViewModel:MYStatusViewModel?{
        didSet{
            
            contentLabel.text = statusViewModel?.retweetContentText
            retweetViewCons?.uninstall()
            // 有配图
            if (statusViewModel?.listModel?.retweeted_status?.pic_urls?.count)! > 0 {
                pictureView.picUrls = statusViewModel?.listModel?.retweeted_status?.pic_urls
                pictureView.isHidden = false
                
                self.snp_makeConstraints { (make) in
                    self.retweetViewCons = make.bottom.equalTo(pictureView).offset(10).constraint
                }
            }else {
                // 没有配图
                pictureView.isHidden = true
                self.snp_makeConstraints { (make) in
                    self.retweetViewCons = make.bottom.equalTo(contentLabel).offset(10).constraint
                }
            }

        }
    }
    
    func setupUI(){
        backgroundColor = UIColor(white: 237/255, alpha: 1)
       addSubview(contentLabel)
        addSubview(pictureView)
        contentLabel.snp_makeConstraints { (make) in
            make.top.left.equalTo(10)
        }
        pictureView.snp_makeConstraints { (make) in
            //            make.size.equalTo(CGSize(width: 100, height: 100))
            make.left.equalTo(contentLabel)
            make.top.equalTo(contentLabel.snp_bottom).offset(10)
        }
        self.snp_makeConstraints { (make) in
          self.retweetViewCons = make.bottom.equalTo(pictureView).offset(10).constraint
        }
    }
    
    
    private lazy var contentLabel :UILabel = UILabel(title: "大哥你好", fontSize: 14, textColor: UIColor.darkGray, axWidth: SCREENWIDTH - 20)
    private lazy var pictureView: MYStatusPictureView = {
        let view = MYStatusPictureView()
        view.backgroundColor = self.backgroundColor
        return view
    }()
}
